package com.tim.app.ui.cell;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.RelativeLayout;

import com.application.library.widget.RatioImageView;
import com.tim.app.R;
import com.tim.app.RT;
import com.tim.app.server.entry.Advertisement;
import com.tim.app.util.BitmapLoader;


public class BannerCell extends RelativeLayout implements ListCell {

    private RatioImageView iv_banner;

    public BannerCell(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        iv_banner = (RatioImageView) findViewById(R.id.iv_banner);
    }

    @Override
    public void onGetData(Object data, int position, BaseAdapter adapter) {
        if (data == null) {
            return;
        }
        this.setLayoutParams(new Gallery.LayoutParams(RT.getScreenWidth(), (int) (RT.getScreenWidth() * 0.4667)));
        Advertisement banner = (Advertisement) data;
        BitmapLoader.ins().loadImage(banner.getImage(), iv_banner);
    }
}
